/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
//		File Name		:		CJCEvent.cpp
//
//		Author			:		Kevin Jordan
//
//		Purpose			:		A header for all functions and members of the Jackie Chan Event Object
//
//		Dates			:		Written( Feb 19, 2011 ) by Kevin Jordan		LastUpdate( Feb 19, 2011  ) by Kevin Jordan 
//	
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#include "CJCEvent.h"
#include "SGD Wrappers/CSGD_DirectInput.h"
#include "SGD Wrappers/CSGD_Direct3D.h"
#include "SGD Wrappers/CSGD_TextureManager.h"
#include "VIN_SoundManager.h"
#include "CGamePlayState.h"
#include "VIN_EventSystem.h"
#include "CTestingLevelState.h"
#include "CHubState.h"



CJCEvent::CJCEvent()
{

	SetPosX(0);
	SetPosY(0);
	SetHeight(128);
	SetWidth(64);
	SetType(EVENT_NULL);
	SetTrigger("NULL");
	ID = CSGD_TextureManager::GetInstance()->LoadTexture("resource/Graphics/KEJ_Dumpster.png");
	m_bInRadius = false;

	ActivationKey = CSGD_TextureManager::GetInstance()->LoadTexture("resource/Graphics/VIN_TKey.png");



}

CJCEvent::~CJCEvent()
{





}

void CJCEvent::Render()
{
	CSGD_Direct3D* pD3D = CSGD_Direct3D::GetInstance();
	CSGD_TextureManager* pTM = CSGD_TextureManager::GetInstance();
	pTM->Draw(ID,(int)GetPosX(),(int)GetPosY());

	/*if( m_bInRadius && CTestingLevelState::GetInstance()->GetTogg() )
	{
		if( !CGamePlayState::GetInstance()->GetTrigEvent() )
		{
			pTM->Draw( ActivationKey, (int)(CHubState::GetInstance()->GetPlayer()->GetPosX()) + (int)(CHubState::GetInstance()->GetPlayer()->GetWidth() * .5f),
				(int)CHubState::GetInstance()->GetPlayer()->GetPosY() - ((int)(CHubState::GetInstance()->GetPlayer()->GetHeight()) + 50 ) );
		}	
	}*/
}


RECT CJCEvent::GetRect()
{

	RECT temp; 
	SetRect( &temp, (int)GetPosX(), (int)GetPosY(), (int)GetPosX() + GetWidth(), (int)GetPosY() + GetHeight() );


	return temp;
}

bool CJCEvent::CheckCollision( IBaseInterface* pBase )
{
	RECT TempRect;

	if(IntersectRect( &TempRect, &this->GetRect(),&pBase->GetRect()))
	return true;

	return false;
}

void CJCEvent::SendTrigger()
{
	void* type = (void*)GetType();
	VIN_EventSystem::GetInstance()->SendEvent("DynTrig",CGamePlayState::GetInstance());
	VIN_EventSystem::GetInstance()->SendEvent("KillAll",CTestingLevelState::GetInstance());

}


void CJCEvent::Update( float fElapsedTime)
{

	CSGD_DirectInput* pDI = CSGD_DirectInput::GetInstance();
	if( m_bInRadius && pDI->KeyPressed(DIK_Z) || CSGD_DirectInput::GetInstance()->JoystickButtonPressed(2) )
	{
		SendTrigger();
		VIN_SoundManager::GetInstance()->PlayExplosion();
	}
	if( CheckCollision(CHubState::GetInstance()->GetPlayer() ) )
	{
		m_bInRadius = true;
	}
	else
		m_bInRadius = false;


}